package cn.yy.aop.util;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
 * jdk动态代理
 * @author Administrator
 *
 */
public class ProxyFactoryBean {

	private static Object target;
	
	private static MyHandler handler;
	//private static InvocationHandler invocationHandler;
	
	//返回一个本类的实例
	public static Object getProxyBean(Object obj,MyHandler hand) throws Exception{
		target=obj;
		handler=hand;
		return Proxy.newProxyInstance(
				target.getClass().getClassLoader(),
				target.getClass().getInterfaces(), 
				//invocationHandler.invoke(proxy, method, args));
				new InvocationHandler() {
					
					public Object invoke(Object proxy, Method method, Object[] args)
							throws Throwable {
						// TODO Auto-generated method stub
						handler.before();
						Object returnValue=method.invoke(target, args);
						handler.after();
						return returnValue;
					}
				}
			);
	}
}
